package hng.controller;


import cn.hutool.log.Log;
import hng.dto.OrderDataDTO;
import hng.service.OrdersService;
import hng.util.JsonData;
import hng.vo.OrderProductVO;
import hng.vo.OrdersDetailVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author 告白
 * @since 2024-06-27
 */
@Slf4j
@RestController
@RequestMapping("/order")
public class OrdersController {

    @Autowired(required = false)
    private OrdersService ordersService;

    /**
     * 用户下单
     */
    @PostMapping("/save-orders")
    public JsonData saveOrders(@RequestBody OrderDataDTO ordersDTO) {
        ordersService.saveOrders(ordersDTO);
        return JsonData.buildSuccess();
    }

    /**
     * 查询订单商品详情
     */
    @GetMapping("/detail")
    public JsonData orderProduct(@RequestParam("orderId") Integer orderId) {
        log.info("orderId: {}", orderId);
        List<OrderProductVO> orderProductVOList = ordersService.getOrderProduct(orderId);
        return JsonData.buildSuccess(orderProductVOList);
    }

    /**
     * 用户查询订单详情
     */
    @GetMapping("/info")
    public JsonData orderInfo(@RequestParam("orderStatus") Integer orderStatus) {
        List<OrdersDetailVO> detailVOList = ordersService.orderInfo(orderStatus);
        return JsonData.buildSuccess(detailVOList);
    }

    /**
     * 用户确认收货
     */
    @GetMapping("/receive-goods")
    public JsonData receiveGoods(@RequestParam("orderId") Integer orderId) {
        ordersService.receiveGoods(orderId);
        return JsonData.buildSuccess();
    }

}

